package com.zcbl.toolkit.logger;

import com.zcbl.common.persistence.annotation.MyBatisDao;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@MyBatisDao
public interface SurveyCaseOperateDAO {


    @Delete({
            "delete from survey_case_operate",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into survey_case_operate (user_id, case_no, ",
            "interface_url, client_ip, ",
            "module_type, operate_des, ",
            "create_time, remark)",
            "values (#{userId,jdbcType=VARCHAR}, #{caseNo,jdbcType=VARCHAR}, ",
            "#{interfaceUrl,jdbcType=VARCHAR}, #{clientIp,jdbcType=VARCHAR}, ",
            "#{moduleType,jdbcType=VARCHAR}, #{operateDes,jdbcType=VARCHAR}, ",
            "#{createTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(SurveyCaseOperate record);

    @InsertProvider(type=SurveyCaseOperateSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(SurveyCaseOperate record);

    @Select({
            "select",
            "id, user_id, case_no, interface_url, client_ip, module_type, operate_des, create_time, ",
            "remark",
            "from survey_case_operate",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="case_no", property="caseNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="interface_url", property="interfaceUrl", jdbcType=JdbcType.VARCHAR),
            @Result(column="client_ip", property="clientIp", jdbcType=JdbcType.VARCHAR),
            @Result(column="module_type", property="moduleType", jdbcType=JdbcType.VARCHAR),
            @Result(column="operate_des", property="operateDes", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
    })
    SurveyCaseOperate selectByPrimaryKey(Long id);

    @UpdateProvider(type=SurveyCaseOperateSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SurveyCaseOperate record);

    @Update({
            "update survey_case_operate",
            "set user_id = #{userId,jdbcType=VARCHAR},",
            "case_no = #{caseNo,jdbcType=VARCHAR},",
            "interface_url = #{interfaceUrl,jdbcType=VARCHAR},",
            "client_ip = #{clientIp,jdbcType=VARCHAR},",
            "module_type = #{moduleType,jdbcType=VARCHAR},",
            "operate_des = #{operateDes,jdbcType=VARCHAR},",
            "create_time = #{createTime,jdbcType=TIMESTAMP},",
            "remark = #{remark,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SurveyCaseOperate record);
}